﻿
using System.Collections.Generic;
using Engine;
using Game;
using GameEntitySystem;
using TemplatesDatabase;
public class 使用2 : SubsystemBlockBehavior, IUpdateable
{
    public SubsystemTerrain m_subsystemTerrain;

    public SubsystemTime m_subsystemTime;

    public SubsystemProjectiles m_subsystemProjectiles;

    public SubsystemParticles m_subsystemParticles;

    public SubsystemAudio m_subsystemAudio;

    public SubsystemNoise m_subsystemNoise;

    public SubsystemPlayers m_subsystemPlayers;

    public SubsystemGameInfo m_subsystemGameInfo;

    public ComponentLevel m_componentLevel;

    public Game.Random m_random = new Game.Random();

    public Dictionary<ComponentMiner, double> m_aimStartTimes = new Dictionary<ComponentMiner, double>();

    public override int[] HandledBlocks
    {
        get
        {
            return new int[]
            {
                    0
            };
        }
    }

    public ComponentPlayer componentPlayer;

    public ComponentMiner componentMiner;

    public IInventory m_inventory;

    public UpdateOrder UpdateOrder
    {
        get
        {
            return 0;
        }
    }

    public void Update(float dt)
    {
    }

    public override bool OnUse(Ray3 ray, ComponentMiner componentMiner)
    {
        int activeBlockValue = componentMiner.ActiveBlockValue;
        int num66 = Terrain.ExtractContents(activeBlockValue);
        BodyRaycastResult? bodyRaycastResult = componentMiner.Raycast<BodyRaycastResult>(ray, RaycastMode.Interaction);
        if (bodyRaycastResult.HasValue)
        {
            ComponentPlayer componentPlayer = componentMiner.ComponentPlayer;
            ComponentHealth componentHealth = bodyRaycastResult.Value.ComponentBody.Entity.FindComponent<ComponentHealth>();
            if (componentHealth.Health > 0f && num66 == 0)
            {
                string entityTemplateName = bodyRaycastResult.Value.ComponentBody.Entity.ValuesDictionary.DatabaseObject.Name;
                Entity entity = DatabaseManager.CreateEntity(Project, entityTemplateName, throwIfNotFound: false);
                ComponentCreature m_componentCreature = bodyRaycastResult.Value.ComponentBody.Entity.FindComponent<ComponentCreature>();
                if (entity != null)
                {
                    if (m_componentCreature.Entity.FindComponent<ComponentChaseBehavior>().m_target == null)
                    {
                        componentMiner.ComponentPlayer.ComponentGui.ModalPanelWidget = new CreatureBagWidget(m_componentCreature);
                        return true;
                    }
                }
            }
            return false;
        }
        return false;
    }


    public override void Load(ValuesDictionary valuesDictionary)
    {
        m_subsystemTerrain = Project.FindSubsystem<SubsystemTerrain>(throwOnError: true);
        m_subsystemPlayers = Project.FindSubsystem<SubsystemPlayers>(throwOnError: true);
        m_subsystemGameInfo = Project.FindSubsystem<SubsystemGameInfo>(throwOnError: true);
        m_subsystemTime = Project.FindSubsystem<SubsystemTime>(throwOnError: true);
        m_subsystemProjectiles = Project.FindSubsystem<SubsystemProjectiles>(throwOnError: true);
        m_subsystemParticles = Project.FindSubsystem<SubsystemParticles>(throwOnError: true);
        m_subsystemAudio = Project.FindSubsystem<SubsystemAudio>(throwOnError: true);
        m_subsystemNoise = Project.FindSubsystem<SubsystemNoise>(throwOnError: true);
        base.Load(valuesDictionary);
    }
}